<%#
 Copyright 2013-2019 the original author or authors from the JHipster project.

 This file is part of the JHipster project, see https://www.jhipster.tech/
 for more information.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-%>
# JHipster Registry HA cluster
#
# As this is based on a StatefulSet, it will only work on OCP >= 1.5/3.5. Please note StatefulSet is yet not a production ready service.
# It is 'BETA' in Kubernetes and 'Technology Preview' in OpenShift 3.5
#
# Registry template. This defines all the configurable parameters and other objects that are needed to run the Eureka service. This
# template can even be saved in OpenShift namespace as well so that have the flexibility to do any project specific customizations. Pls
# note wherever displayName says *** PLEASE DO NOT CHANGE THIS ***, don't touch that as those parameters will be referenced in other places.
#
apiVersion: <%= KUBERNETES_CORE_API_VERSION  %>
kind: Template
metadata:
  name: jhipster-registry-template
  namespace: <%= openshiftNamespace %>
  annotations:
    description: This template defines objects that are required to spin up an jhipster-registry pod
    tags: jhipster-registry, eureka, spring-cloud
    openshift.io/display-name: jhipster-registry-template
    openshift.io/long-description: "This template provides objects that are required to spin up a jhipster-registry pod."
    openshift.io/provider-display-name: JHipster
labels:
  app: jhipster-registry
  createdBy: JHipster-Team
parameters:
  -
    name: APPLICATION_NAME
    value: jhipster-registry
    description: Name of the application
    required: true
    displayName: Application Name
  -
    name: SECRET_REF
    value: reg-secret-ref
    description: Name of the application
    required: true
    displayName: "*** PLEASE DO NOT CHANGE THIS ***"
objects:
  -
    apiVersion: <%= KUBERNETES_CORE_API_VERSION  %>
    kind: Secret
    metadata:
      name: ${SECRET_REF}
    type: Opaque
    data:
      registry-admin-password: <%= adminPasswordBase64 %> # base64 encoded "<%= adminPassword %>"
  -
    apiVersion: <%= KUBERNETES_STATEFULSET_API_VERSION %>
    kind: StatefulSet
    metadata:
      name: ${APPLICATION_NAME}
    spec:
      serviceName: ${APPLICATION_NAME}
      replicas: "<%= registryReplicas %>"
      template:
        metadata:
          labels:
            app: ${APPLICATION_NAME}
        spec:
          terminationGracePeriodSeconds: 10
          containers:
          - name: ${APPLICATION_NAME}
            image: <%= DOCKER_JHIPSTER_REGISTRY %>
            ports:
            - name: http
              containerPort: 8761
            env:
            # Registry configuration
            - name: SPRING_PROFILES_ACTIVE
              value: prod,k8s
            - name: SPRING_SECURITY_USER_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: ${SECRET_REF}
                  key: registry-admin-password
            - name: JHIPSTER_SECURITY_AUTHENTICATION_JWT_BASE64_SECRET
              value: YlhrdGMyVmpjbVYwTFhSdmEyVnVMWFJ2TFdOb1lXNW5aUzFwYmkxd2NtOWtkV04wYVc5dUxXRnVaQzEwYnkxclpXVndMV2x1TFdFdGMyVmpkWEpsTFhCc1lXTmwK
            - name: SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_TYPE
              value: native
            - name: SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_SEARCH_LOCATIONS
              value: file:./central-config
            - name: EUREKA_INSTANCE_LEASE_RENEWAL_INTERVAL_IN_SECONDS
              value: '15'
            - name: EUREKA_INSTANCE_LEASE_EXPIRATION_DURATION_IN_SECONDS
              value: '30'
            - name: EUREKA_SERVER_PEER_EUREKA_NODES_UPDATE_INTERVAL_MS
              value: '15000'
            - name: EUREKA_SERVER_RENAWAL_THRESHOLD_UPDATE_INTERVAL_MS
              value: '15000'
            - name: EUREKA_SERVER_REGISTRY_SYNC_RETRIES
              value: '3'
            - name: EUREKA_SERVER_ENABLE_SELF_PRESERVATION
              value: 'false'
            - name: EUREKA_SERVER_PEER_NODE_CONNECT_TIMEOUT_MS
              value: '2000'
            - name: EUREKA_CLIENT_FETCH_REGISTRY
              value: 'true'
            - name: EUREKA_CLIENT_REGISTER_WITH_EUREKA
              value: 'true'
            - name: K8S_CONFIG_PATH
              value: '/central-config/'
            volumeMounts:
            - name: config-volume
              mountPath: /central-config
          volumes:
          - name: config-volume
            configMap:
              name: application-config
  -
    apiVersion: <%= KUBERNETES_CORE_API_VERSION  %>
    kind: Service
    metadata:
      name: ${APPLICATION_NAME}
      labels:
        app: ${APPLICATION_NAME}
      annotations:
        service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
    spec:
      ports:
      - name: http-bc
        port: 8761
        targetPort: 8761
      - name: http
        port: 80
        targetPort: 8761
      clusterIP: None
      selector:
        app: ${APPLICATION_NAME}
  -
    apiVersion: <%= KUBERNETES_CORE_API_VERSION  %>
    kind: Route
    metadata:
      name: ${APPLICATION_NAME}
    spec:
      to:
        kind: Service
        name: ${APPLICATION_NAME}
        weight: 100
      port:
        targetPort: http
      wildcardPolicy: None
